package com.erlang.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Description：基础数据类型接受
 */
@Controller
@RequestMapping(value = "basic-type")
public class BasicTypeController {

    /**
     * @Description 去操作页面
     */
    @RequestMapping(value = "to-basic-type")
    public ModelAndView toBasicType(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("basic-type");
        return modelAndView;
    }

    /**
     * 不建议使用简单类型的基础类型（int）。原因是基础类型不能为null值，如果不传递会报异常
     *
     * @Description 接受表单
     *
     */
    @RequestMapping(value = "do-basic-type")
    public ModelAndView doBasicType(@RequestParam(value = "id",required = false,defaultValue = "1") Integer id){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("id", id);
        modelAndView.setViewName("basic-type");
        return modelAndView;
    }
}